$(function() {
    setupPhotoGallery();
});

function setupPhotoGallery() {
    var photos = $('.gallery a.popup');
    $('.gallery').parent().append('<div id="photospaging">')
    for (var c = 0; c < photos.size(); c += 8) {
        photos.slice(c, c + 8).wrapAll('<div class="photosspage"/>');
    }
    $('.gallery').cycle({fx: 'fade', fit: 1, containerResize: 0, timeout: 0, cleartype: 0, pager: '#photospaging'});
}